class MyException(Exception):

    def __init__(self, msg):
        self.msg = msg

    def __str__(self):
        return self.msg


def name_input():
    name = input("请输入姓名：")
    name = name.strip()
    if name == "":
        raise MyException("姓名不能为空")
    elif len(name) > 4:
        raise MyException("姓名长度不能超过4")

    for ele in name:
        if ele.isdigit():
            raise MyException("不能包含数字")

    # aa = 10 / 0 # 触发 ZeroDivisionError 异常

    return name


while True:
    try:
        name = name_input()
        print(name)
    except MyException as e:
        print("自定义异常：", e)
    except ZeroDivisionError:
        print("除零异常：")
    except (IndexError, KeyError):
        print("其他异常")
    except Exception as e:
        print(e)
